﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Portal.Web.Utility;
using Portal.Core;
using Portal.Exam.Model;
using Portal.Exam.Bussiness;
using Portal.Systems.Model;
using Portal.Web.Model;

namespace Portal.Exam.Render
{
    public class DoExamRenderBll
    {
        internal static bool HasShutdownStarted = false;
        static string GetExamConnectionString(string SiteId)
        {
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            string ExamConnectionString = WebConfig.GetConfigFromXml(OSiteParam, "ExamConnectionString");
            return ExamConnectionString;
        }

        public static string ConvertSecondToMinutes(int TotalExamTime)
        {
            string ClassRemainTime = "cssTotalTime";
            if (TotalExamTime <= 5)
            {
                ClassRemainTime = "cssTotalTimeBlink";
            }

            return "<span class=" + ClassRemainTime + ">" + TotalExamTime.ToString("#,#00") + " phút</span>";

        }

        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string tid = (string)WebEnvironments.Request(SiteId, "tid");
                if (string.IsNullOrEmpty(tid)) throw new Exception("Truy cập không hợp lệ!");
                ExamRoomStudentCls OExamRoomStudent = new ExamRoomStudentBll().CreateModel(SiteId, tid);
                if (OExamRoomStudent == null) throw new Exception(ExamUltility.AccessDenied);
                string ExamRoomStudentId = OExamRoomStudent.ExamRoomStudentId;
                UserCls OLoginStudent = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CreateUserModel(SiteId, OExamRoomStudent.StudentCode);
                WebSessionUtility.SetCurrentLoginUser(OLoginStudent);

                string g = (string)WebEnvironments.Request(SiteId, "g");
                if (g == null) g = "1";
                g = g.ToLower();
                //update use time                
                new DoExamBll().UpdateUseTime(null, SiteId, ExamRoomStudentId);

                string Html =
                    "<script language=javascript>\r\n" +
                    "       ProgressBarIndex=0;\r\n" +
                    "       function setProgressBar()\r\n" +
                    "       {\r\n" +
                    "           SiteId='" + SiteId + "';\r\n" +
                    "           document.getElementById(\"divInfoBottom\").innerHTML=Portal.Exam.Render.DoExamRenderBll.ServerSideGetProgressBar(SiteId, ProgressBarIndex).value;\r\n" +
                    "           ProgressBarIndex=ProgressBarIndex+1;\r\n" +
                    "           if(ProgressBarIndex==60)ProgressBarIndex=0;\r\n" +
                    "           setTimeout(\"setProgressBar()\",1000);\r\n" +
                    "       } \r\n" +

                    " function DoNextQuestion(ExamRoomStudentId,g,CurrentIndex) \r\n" +
                    " { \r\n" +
                    "     SiteId='" + SiteId + "';\r\n" +
                    "     retValue=Portal.Exam.Render.DoExamRenderBll.GetFormContent(SiteId, ExamRoomStudentId,g,CurrentIndex).value; \r\n" +
                    "     document.getElementById(\"divFormExamContent\").innerHTML=retValue; \r\n" +
                    " } \r\n" +

                    " function DoGoQuestion(ExamRoomStudentId, g, CurrentIndex)  \r\n" +
                    " { \r\n" +
                    "     SiteId='" + SiteId + "';\r\n" +
                    "     retValue = Portal.Exam.Render.DoExamRenderBll.GetFormContent(SiteId, ExamRoomStudentId, g, CurrentIndex).value; \r\n" +
                    "     document.getElementById(\"divFormExamContent\").innerHTML = retValue; \r\n" +
                    " } \r\n" +


                    " function DoBackQuestion(ExamRoomStudentId,g,CurrentIndex) \r\n" +
                    " { \r\n" +
                    "     SiteId='" + SiteId + "';\r\n" +
                    "     retValue=Portal.Exam.Render.DoExamRenderBll.GetFormContent(SiteId, ExamRoomStudentId,g,CurrentIndex).value; \r\n" +
                    "     document.getElementById(\"divFormExamContent\").innerHTML=retValue; \r\n" +
                    " } \r\n" +

                    " function DoCheckBestAnswer(ExamQuestionId,ExamAnswerId) \r\n" +
                    " { \r\n" +
                    "     SiteId='" + SiteId + "';\r\n" +
                    "     ExamRoomStudentId=document.getElementById(\"txtExamRoomStudentId\").value; \r\n" +
                    "     retValue=Portal.Exam.Render.DoExamRenderBll.GetCheckedBestAnswer(SiteId, ExamQuestionId, ExamRoomStudentId, ExamAnswerId).value; \r\n" +
                    "     document.getElementById(\"divBestAnswerContent\").innerHTML=retValue; \r\n" +
                    " } \r\n" +

                    //" function DoSelectAnswer(ExamQuestionId,ExamAnswerId) \r\n" +
                    //" { \r\n" +
                    //"     SiteId='" + SiteId + "';\r\n" +
                    //"     ExamRoomStudentId=document.getElementById(\"txtExamRoomStudentId\").value; \r\n" +
                    //"     retValue=Portal.Exam.Render.DoExamRenderBll.GetSelectedAnswer(SiteId, ExamQuestionId, ExamRoomStudentId, ExamAnswerId).value; \r\n" +
                    //"     document.getElementById(\"divBestAnswerContent\").innerHTML=retValue; \r\n" +
                    //" } \r\n" +

                    " function SetFinishExam(ExamRoomStudentId) \r\n" +
                    " { \r\n" +
                    "     SiteId='" + SiteId + "';\r\n" +
                    "     ConfirmMsg=Portal.Exam.Render.DoExamRenderBll.GetConfirmFinishExamMsg(SiteId).value; \r\n" +
                    "     if(confirm(ConfirmMsg)==false)return; \r\n" +
                    "     OAjaxOut=Portal.Exam.Render.DoExamRenderBll.ServerSideSetFinishExam(SiteId, ExamRoomStudentId).value; \r\n" +
                    "     if(OAjaxOut.Error)\r\n" +
                    "     {\r\n" +
                    "           alert(OAjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "     }\r\n" +
                    "     window.open(OAjaxOut.RetUrl,'_self');\r\n" +
                    " } \r\n" +

                    " function DoCheckNeedReview(ExamQuestionId,ExamRoomStudentId) \r\n" +
                    " { \r\n" +
                    "     SiteId='" + SiteId + "';\r\n" +
                    "     needReview=document.getElementById(\"chkNeedReview\").checked; \r\n" +
                    "     retValue=Portal.Exam.Render.DoExamRenderBll.SetNeedReview(SiteId, ExamQuestionId,ExamRoomStudentId,needReview).value; \r\n" +
                    "     if(retValue.indexOf(\"ERROR\")!=-1) \r\n" +
                    "     { \r\n" +
                    "         alert(retValue); \r\n" +
                    "         return; \r\n" +
                    "     } \r\n" +
                    " } \r\n" +


                    " function SaveAnswerItem(ExamQuestionId,WhoIsExamId,g,NextIndex,iNext,Type) \r\n" +
                    " { \r\n" +
                    "     SiteId='" + SiteId + "';\r\n" +
                    "     ExamRoomStudentId=document.getElementById(\"txtExamRoomStudentId\").value; \r\n" +
                    "     qType=document.getElementById(\"txtQuestionType\").value; \r\n" +

                    "     if(qType==\"yesno\") \r\n" +
                    "     { \r\n" +
                    "         selectIndexYesNo=document.getElementById(\"drpYesNo\").selectedIndex; \r\n" +
                    "         cValue=document.getElementById(\"drpYesNo\").options[selectIndexYesNo].value; \r\n" +
                    "         retValue=Portal.Exam.Render.DoExamRenderBll.SaveYesNoAnswer(SiteId, ExamQuestionId,ExamRoomStudentId,cValue).value; \r\n" +
                    "     } \r\n" +

                    "     if(qType==\"bestanswer\") \r\n" +
                    "     { \r\n" +
                    "         MaxAnsItems=document.getElementById(\"txtMaxItemAns\").value; \r\n" +
                    "         for(var iIndex=0;iIndex<MaxAnsItems;iIndex++) \r\n" +
                    "         { \r\n" +
                    "             checked=document.getElementById(\"txtItemAns\"+iIndex).checked; \r\n" +
                    "             if(checked==true) \r\n" +
                    "             { \r\n" +
                    "                 ExamAnswerId=document.getElementById(\"txtItemAnsId\"+iIndex).value; \r\n" +
                    "                 retValue=Portal.Exam.Render.DoExamRenderBll.SaveBestAnswer(SiteId, ExamQuestionId,ExamRoomStudentId,ExamAnswerId).value; \r\n" +
                    "             } \r\n" +
                    "         } \r\n" +
                    "     } \r\n" +

                    "     if(qType==\"crosslink\" || qType==\"image\") \r\n" +
                    "     { \r\n" +
                    "         MaxAnsItems=document.getElementById(\"txtMaxItemAns\").value; \r\n" +
                    "         var StudentAnswer = ''; \r\n " +
                    "         var StudentAnswerKeyValue = ''; \r\n " +
                    "         for(var iIndex=0;iIndex<MaxAnsItems;iIndex++) \r\n" +
                    "         { \r\n" +
                    "               var e = document.getElementById(\"drpCrossLink\"+iIndex); \r\n" +
                    "               var value = e.options[e.selectedIndex].value; \r\n" +
                    //"             value=document.getElementById(\"txtItemAnsIdPA2\"+iIndex).value; \r\n" +
                    "             if(isNaN(value)) {  \r\n" +
                    "             alert('Yêu cầu nhập câu trả lời bằng số!');   \r\n" +
                    "             return ; " +
                    "             }else {  \r\n" +
                    "                   value=value - 1; \r\n" +
                    "                   if(document.getElementById(\"txtItemAnsId\"+value)!=null){ \r\n" +
                    "                       ExamAnswerId=document.getElementById(\"txtItemAnsId\"+value).value; \r\n" +
                    "                   } else \r\n" +
                    "                   { \r\n" +
                    "                       ExamAnswerId= '' \r\n" +
                    "                   } \r\n" +
                    "                 ExamAnswerIdPA2=document.getElementById(\"txtPA2ItemAnsId\"+iIndex).value; \r\n" +
                    "                 StudentAnswerKeyValue=StudentAnswerKeyValue + ExamAnswerId + \":\" + ExamAnswerIdPA2  + \"|\"; \r\n" +
                    "                 StudentAnswer=StudentAnswer + (value + 1) + \":\" + ExamAnswerIdPA2  + \"|\"; \r\n" +
                    "               } \r\n" +
                    "         } \r\n" +
                    "                 retValue=Portal.Exam.Render.DoExamRenderBll.SaveCrossLinkAnswer(SiteId, ExamQuestionId,ExamRoomStudentId,StudentAnswer,StudentAnswerKeyValue).value; \r\n" +
                    "     } \r\n" +



                #region old
                    //"     if(qType==\"crosslink\" || qType==\"image\") \r\n" +
                    //"     { \r\n" +
                    //"         MaxAnsItems=document.getElementById(\"txtMaxItemAns\").value; \r\n" +
                    //"         var StudentAnswer = ''; \r\n " +
                    //"         var StudentAnswerKeyValue = ''; \r\n " +
                    //"         for(var iIndex=0;iIndex<MaxAnsItems;iIndex++) \r\n" +
                    //"         { \r\n" +
                    //"             value=document.getElementById(\"txtItemAnsIdPA2\"+iIndex).value; \r\n" +
                    //"             if(isNaN(value)) {  \r\n" +
                    //"             alert('Yêu cầu nhập câu trả lời bằng số!');   \r\n" +
                    //"             return ; " +
                    //"             }else {  \r\n" +
                    //"                   value=value - 1; \r\n" +
                    //"                   if(document.getElementById(\"txtItemAnsId\"+value)!=null){ \r\n" +
                    //"                       ExamAnswerId=document.getElementById(\"txtItemAnsId\"+value).value; \r\n" +
                    //"                   } else \r\n" +
                    //"                   { \r\n" +
                    //"                       ExamAnswerId= '' \r\n" +
                    //"                   } \r\n" +
                    //"                 ExamAnswerIdPA2=document.getElementById(\"txtPA2ItemAnsId\"+iIndex).value; \r\n" +
                    //"                 StudentAnswerKeyValue=StudentAnswerKeyValue + ExamAnswerId + \":\" + ExamAnswerIdPA2  + \"|\"; \r\n" +
                    //"                 StudentAnswer=StudentAnswer + (value + 1) + \":\" + ExamAnswerIdPA2  + \"|\"; \r\n" +
                    //"               } \r\n" +
                    //"         } \r\n" +
                    //"                 retValue=Portal.Exam.Render.DoExamRenderBll.SaveCrossLinkAnswer(SiteId, ExamQuestionId,ExamRoomStudentId,StudentAnswer,StudentAnswerKeyValue).value; \r\n" +
                    //"     } \r\n" +
                #endregion

                    "     if(qType==\"truefalse\") \r\n" +
                    "     { \r\n" +
                    "         MaxAnsItems=document.getElementById(\"txtMaxItemAns\").value; \r\n" +
                    "         var StudentAnswer = ''; \r\n " +
                    "         for(var iIndex=0;iIndex<MaxAnsItems;iIndex++) \r\n" +
                    "         { \r\n" +
                    "               var e = document.getElementById(\"drpYesNo\"+iIndex); \r\n" +
                    "               var value = e.options[e.selectedIndex].value; \r\n" +
                    "             if(value==1) \r\n" +
                    "             { \r\n" +
                    "                 ExamAnswerId=document.getElementById(\"txtItemAnsId\"+iIndex).value; \r\n" +
                    "                 StudentAnswer=StudentAnswer+ExamAnswerId+\"|\"; \r\n" +
                    "             } \r\n" +
                    "         } \r\n" +
                    "         retValue=Portal.Exam.Render.DoExamRenderBll.SaveTrueFalse(SiteId, ExamQuestionId,ExamRoomStudentId,StudentAnswer).value; \r\n" +
                    "     } \r\n" +

                    "     if(qType==\"multichoice\") \r\n" +
                    "     { \r\n" +
                    "         MaxAnsItems=document.getElementById(\"txtMaxItemAns\").value; \r\n" +
                    "         var StudentAnswer=\"\"; \r\n" +
                    "         for(var iIndex=0;iIndex<MaxAnsItems;iIndex++) \r\n" +
                    "         { \r\n" +
                    "             checked=document.getElementById(\"txtItemAns\"+iIndex).checked; \r\n" +
                    "             if(checked) \r\n" +
                    "             { \r\n" +
                    "                 ExamAnswerId=document.getElementById(\"txtItemAnsId\"+iIndex).value; \r\n" +
                    "                 StudentAnswer=StudentAnswer+ExamAnswerId+\"|\"; \r\n" +
                    "             } \r\n" +
                    "         } \r\n" +
                    "         retValue=Portal.Exam.Render.DoExamRenderBll.SaveMultiChoice(SiteId, ExamQuestionId,ExamRoomStudentId,StudentAnswer).value; \r\n" +
                    "     } \r\n" +

                    "     if(qType==\"flash\") \r\n" +
                    "     { \r\n" +
                    "         AnswerFlash=document.getElementById(\"txtAnswerFlash\").value; \r\n" +
                    "         retValue=Portal.Exam.Render.DoExamRenderBll.SaveFlash(SiteId, ExamQuestionId,ExamRoomStudentId,AnswerFlash).value; \r\n" +
                    "         if(retValue.indexOf('ERROR')!=-1)\r\n" +
                    "         {\r\n" +
                    "               alert(retValue);\r\n" +
                    "               document.getElementById(\"txtAnswerFlash\").focus();\r\n" +
                    "               document.getElementById(\"txtAnswerFlash\").select();\r\n" +
                    "               return;\r\n" +
                    "         }\r\n" +
                    "     } \r\n" +

                    "     if(qType==\"freetext\") \r\n" +
                    "     { \r\n" +
                    "         FreeTextContent=document.getElementById(\"txtFreeTextContent\").value; \r\n" +
                    "         retValue=Portal.Exam.Render.DoExamRenderBll.SaveFreeText(SiteId, ExamQuestionId,ExamRoomStudentId,FreeTextContent).value; \r\n" +
                    "     } \r\n" +
                    "     if(qType==\"largefreetext\") \r\n" +
                    "     { \r\n" +
                    "         FreeTextContent=document.getElementById(\"txtFreeTextContent\").value; \r\n" +
                    "         retValue=Portal.Exam.Render.DoExamRenderBll.SaveFreeText(SiteId, ExamQuestionId,ExamRoomStudentId,FreeTextContent).value; \r\n" +
                    "     } \r\n" +
                    "     if(iNext==1)DoNextQuestion(WhoIsExamId,g,NextIndex); \r\n" +
                    "     if(qType==\"flash\") \r\n" +
                    "     {\r\n" +
                    "           document.getElementById(\"txtAnswerFlash\").focus();\r\n" +
                    "           document.getElementById(\"txtAnswerFlash\").select();\r\n" +
                    "     }\r\n" +
                    " } \r\n" +

                    " function DoStartMemory(ExamRoomStudentId,ExamQuestionId, g, CurrentIndex) \r\n" +
                    " { \r\n" +
                    "     SiteId='" + SiteId + "';\r\n" +
                    "     retValue=Portal.Exam.Render.DoExamRenderBll.SetStartQuestionMemory(SiteId, ExamRoomStudentId,ExamQuestionId,g,CurrentIndex).value; \r\n" +
                    "     if(retValue.indexOf(\"ERROR\")!=-1) \r\n" +
                    "     { \r\n" +
                    "         alert(retValue); \r\n" +
                    "         return; \r\n" +
                    "     } \r\n" +
                    "     document.getElementById(\"divFormExamContent\").innerHTML = retValue;    \r\n" +
                    " } \r\n" +

                    //"   function ClientMakeNewExam()\r\n" +
                    //"   {\r\n" +
                    //"     SiteId='" + SiteId + "';\r\n" +
                    //"     AjaxOut=Portal.Exam.Render.DoExamRenderBll.ServerSideNewExam(SiteId, ExamTemplateId).value; \r\n" +
                    //"     if(AjaxOut.Error) \r\n" +
                    //"     { \r\n" +
                    //"         alert(AjaxOut.InfoMessage); \r\n" +
                    //"         return; \r\n" +
                    //"     } \r\n" +
                    //"     window.open('DoExam.aspx?tid='+ExamTemplateId,'_self');\r\n" +
                    //"   }\r\n" +
                    "</script>\r\n" +
                    "<div id=divFormExamContent>" + GetFormContent(SiteId, ExamRoomStudentId, g, 0) + "</div>";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;

        }
        public static void SaveBytesToFile(string File, byte[] b)
        {
            FileStream fs = new FileStream(File, FileMode.Create);
            fs.Write(b, 0, b.Length);
            fs.Close();
        }

        public static string ExamConnectionString(string SiteId)
        {
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            string ExamConnectionString = WebConfig.GetConfigFromXml(OSiteParam, "ExamConnectionString");
            return ExamConnectionString;
        }

        public static string GetEmbbedContent(string SiteId, string ExamQuestionId)
        {
            byte[] outbyte = null;
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            try
            {
                string SaveFile = OSiteParam.PathRoot + "\\ExamFlash";
                System.IO.Directory.CreateDirectory(SaveFile);
                SaveFile = SaveFile + "\\" + ExamQuestionId + ".swf";
                if (!File.Exists(SaveFile))
                {
                    string Query = "select [ExamEmbbedHtml] from [TableExamQuestion] where ExamQuestionId=@ExamQuestionId";
                    SqlCommand SqlCommand = new System.Data.SqlClient.SqlCommand(Query, new SqlConnection(GetExamConnectionString(SiteId)));
                    SqlCommand.Connection.Open();
                    SqlCommand.Parameters.Add("@ExamQuestionId", SqlDbType.VarChar).Value = ExamQuestionId;
                    SqlDataAdapter sqlda = new SqlDataAdapter(SqlCommand);
                    DataTable dtResult = new DataTable();
                    sqlda.Fill(dtResult);
                    if (dtResult.Rows[0]["ExamEmbbedHtml"] == DBNull.Value) return null;
                    outbyte = (byte[])dtResult.Rows[0]["ExamEmbbedHtml"];
                    SaveBytesToFile(SaveFile, outbyte);
                }
                string Url = OSiteParam.HttpRoot + "/ExamFlash/" + ExamQuestionId + ".swf";
                return "<iframe src=\"" + Url + "\" width=640 height=450></iframe>\r\n";
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideNewExam(string SiteId, string ExamTemplateId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                new ExamTemplateBll().CreateExamForUniNetTest(SiteId, ExamTemplateId, true);
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod]
        public static string GetFormContent(string SiteId, string ExamRoomStudentId, string g, int CurrentIndex)
        {
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            try
            {
                if (g == null) g = "1";
                g = g.ToLower();
                ExamRoomStudentCls OExamRoomStudent = new ExamRoomStudentBll().CreateModel(SiteId, ExamRoomStudentId);
                if (OExamRoomStudent == null)
                {
                    return
                        "Không tìm thấy bài kiểm tra online này";
                }

                string FinishButton = "<input class=button type=button onclick=javascript:SetFinishExam('" + ExamRoomStudentId + "'); type=button value=\"Kết thúc bài làm\">";
                if (OExamRoomStudent.FinishExam == 1)
                {
                    FinishButton = "";
                }

                string LayoutText =

                    "<div class=DoFormExam>\r\n" +
                    "<div class=studentinfo>Thí sinh: " + OExamRoomStudent.StudentCode + " - " + OExamRoomStudent.StudentName + " / Lớp: " + OExamRoomStudent.Class + " - khóa: " + OExamRoomStudent.Course + "</div>\r\n" +
                    "<div class=examheader>\r\n" +
                    "   <h3>{0}</h3>\r\n" +
                    "</div>\r\n" +
                    "<table>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=col1>\r\n" +
                    "           <div class=\"post_body\"> \r\n" +
                    "               {1}\r\n" +
                    "           </div> \r\n" +//post_body
                    "       </td>\r\n" +
                    "       <td class=col2>\r\n" +
                    "           <div class=\"sidebartop\"></div>\r\n" +
                    "           <div class=\"sidebar\"> \r\n" +
                    "               {3}" +
                    "           </div> \r\n" +
                    "           <div class=\"sidebar\"> \r\n" +
                    "               {4}" +//thong so da lam duoc may cau con bao cau
                    "           </div> \r\n" +
                    "           <div class=\"sidebar\"> \r\n" +
                    "               {5}" +//next back
                    "           </div> \r\n" +
                    "       </td>\r\n" +
                    "   </tr>\r\n" +
                    "</table>\r\n" +
                    "</div>\r\n";

                //ExamTemplateCls ExamTemplateCls = new ExamTemplateBll().CreateModel(SiteId, OExamRoomStudent.ExamTemplateId);
                if (OExamRoomStudent.HasGenQuestion == 0)
                {
                    return "<div class=CssNoData>Bài kiểm tra chưa sẵn sàng! <input type=button value=\"Khởi tạo lại bài kiểm tra\" onclick=\"javascript:ClientMakeNewExam();\"></div>";
                }

                string ExamTitle = OExamRoomStudent.ExamTitle;
                if (OExamRoomStudent.FinishExam == 1)
                {
                    ExamTitle = ExamTitle + " / đã hoàn thành";
                }
                System.Web.HttpContext.Current.Session["ExamTitle"] = ExamTitle;
                int qn = CurrentIndex;

                if (qn >= OExamRoomStudent.TotalQuestion)
                {
                    qn = OExamRoomStudent.TotalQuestion - 1;
                }
                int NextIndex = qn + 1;
                if (NextIndex >= OExamRoomStudent.TotalQuestion)
                {
                    NextIndex = OExamRoomStudent.TotalQuestion - 1;
                }
                ExamQuestionCls examQuestionCls = new ExamQuestionBll().CreateModelByIndex(SiteId, ExamRoomStudentId, qn);
                if (examQuestionCls == null)
                {
                    return "<div class=cssExamError>Xin lỗi vì đã không tìm thấy câu hỏi này!</div>";
                }

                string NextUrl = "onclick=javascript:DoNextQuestion('" + ExamRoomStudentId + "','" + g + "'," + (qn + 1) + ");";
                string BackUrl = "onclick=javascript:DoBackQuestion('" + ExamRoomStudentId + "','" + g + "'," + (qn - 1) + ");";

                if (qn == OExamRoomStudent.TotalQuestion - 1)
                {
                    NextUrl = "";
                }
                if (qn == 0)
                {
                    BackUrl = "";
                }
                string CheckedReviewText = "";
                if (examQuestionCls.MarkedNeedReview == 1)
                {
                    CheckedReviewText = "checked";
                }

                string AnsText = "";
                string Header = "  <tr><td class=\"tdFirstColAnswer\" style=\"width:70%;\"></td><td style=\"width:15%;\"><b>Sinh viên trả lời</b></td><td style=\"width:15%;\"><b>Câu trả lời</b></td></tr>";

                DataTable dtItems = new ExamQuestionBll().ReadingExamAnswer(SiteId, examQuestionCls.ExamQuestionId);
                int items = dtItems.Rows.Count;
                string Selected = "";

                //************** multichoice *****************************
                if (examQuestionCls.Type.ToLower().Equals("multichoice"))
                {
                    string[] Answers = examQuestionCls.StudentAnswer.Split(new char[] { '|' });

                    AnsText +=
                        "<div class=cssHelpExam>Chọn vào <b>các phương án đúng</b> trong các phương án dưới đây</div>" +
                        "<div id=divBestAnswerContent>" +
                        "<input type=hidden id=txtMaxItemAns value=\"" + items + "\">" +
                        "<table class=cssUlAnswerText>";

                    for (int iIndex = 0; iIndex < items; iIndex++)
                    {
                        string tExamAnswerId = (string)dtItems.Rows[iIndex]["ExamAnswerId"];
                        string tAnswerTextFirst = (string)dtItems.Rows[iIndex]["AnswerTextFirst"];
                        bool CheckMarked = false;
                        for (int iIndexCheck = 0; iIndexCheck < Answers.Length; iIndexCheck++)
                        {
                            if (Answers[iIndexCheck].Trim().Length > 0)
                            {
                                if (Answers[iIndexCheck].Equals(tExamAnswerId))
                                {
                                    CheckMarked = true;
                                }
                            }
                        }
                        if (OExamRoomStudent.FinishExam == 0)
                        {
                            if (CheckMarked)
                            {
                                AnsText += "  <tr><td class=\"tdFirstColAnswer\" style=\"width:15px;\"><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><input id=txtItemAns" + iIndex + " type=checkbox style=\"border:solid 1px silver;padding:1px;\" checked ></td><td>" + tAnswerTextFirst + "</td></tr>";
                            }
                            else
                            {
                                AnsText += "  <tr><td class=\"tdFirstColAnswer\" style=\"width:15px;\"><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><input id=txtItemAns" + iIndex + " type=checkbox style=\"border:solid 1px silver;padding:1px;\"></td><td>" + tAnswerTextFirst + "</td></tr>";
                            }
                        }
                        else
                        {
                            string StudyAns = string.Empty;
                            if (CheckMarked)
                            {
                                StudyAns = "X";
                            }
                            else
                            {
                                StudyAns = "";
                            }

                            AnsText += Header;
                            Header = string.Empty;
                            string tCorrectAnswer = (string)dtItems.Rows[iIndex]["CorrectAnswer"];
                            string CssCorrect = "";

                            if (tCorrectAnswer.Equals("YES"))
                            {
                                CssCorrect = " class=\"cssCorrectAnsLine\"";
                                //}
                                //if (CheckMarked)
                                //{
                                AnsText += "  <tr><td><span" + CssCorrect + ">" + tAnswerTextFirst + "</span></td><td>" + StudyAns + "</td><td>Đúng</td></tr>";
                            }
                            else
                            {
                                AnsText += "  <tr><td><span" + CssCorrect + ">" + tAnswerTextFirst + "</span></td><td>" + StudyAns + "</td><td>Sai</td></tr>";
                            }
                        }
                    }
                    AnsText += "</table>" +
                               "</div>";
                }
                //************** bestanswer *****************************
                if (examQuestionCls.Type.ToLower().Equals("bestanswer"))
                {
                    AnsText =
                              "<div class=cssHelpExam>Chọn 1 phương án đúng nhất trong các phương án dưới đây</div>" +
                              "<div id=divBestAnswerContent>" +
                              "<input type=hidden id=txtMaxItemAns value=\"" + items + "\">" +
                              "<table class=cssUlAnswerText>";
                    Header = "  <tr><td class=\"tdFirstColAnswer\" style=\"width:50%;\"></td><td><b>Sinh viên trả lời</b></td><td><b>Câu trả lời</b></td></tr>";
                    for (int iIndex = 0; iIndex < items; iIndex++)
                    {
                        string tExamAnswerId = (string)dtItems.Rows[iIndex]["ExamAnswerId"];
                        string tAnswerTextFirst = (string)dtItems.Rows[iIndex]["AnswerTextFirst"];
                        string tCorrectAnswer = (string)dtItems.Rows[iIndex]["CorrectAnswer"];
                        string StudyAns = string.Empty;
                        if (OExamRoomStudent.FinishExam == 0)
                        {
                            if (tExamAnswerId.Equals(examQuestionCls.StudentAnswer))
                            {
                                AnsText += "  <tr><td class=\"tdFirstColAnswer\" style=\"width:15px;\"><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><input id=txtItemAns" + iIndex + " onchange=javascript:DoCheckBestAnswer('" + examQuestionCls.ExamQuestionId + "','" + tExamAnswerId + "'); type=checkbox style=\"border:solid 1px silver;padding:1px;\" checked></td><td>" + tAnswerTextFirst + "</td></tr>";
                            }
                            else
                            {
                                AnsText += "  <tr><td class=\"tdFirstColAnswer\" style=\"width:15px;\"><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><input id=txtItemAns" + iIndex + " onchange=javascript:DoCheckBestAnswer('" + examQuestionCls.ExamQuestionId + "','" + tExamAnswerId + "'); type=checkbox style=\"border:solid 1px silver;padding:1px;\" ></td><td>" + tAnswerTextFirst + "</td></tr>";
                            }
                        }
                        else
                        {
                            AnsText += Header;
                            Header = string.Empty;
                            if (tExamAnswerId.Equals(examQuestionCls.StudentAnswer))
                            {
                                StudyAns = "X";
                            }
                            else
                            {
                                StudyAns = "";
                            }

                            string CssCorrect = "";
                            if (tCorrectAnswer.Equals("YES"))
                            {
                                CssCorrect = " class=\"cssCorrectAnsLine\"";
                                //}
                                //if (tExamAnswerId.Equals(examQuestionCls.StudentAnswer))
                                //{
                                AnsText += "  <tr><td><span " + CssCorrect + ">" + tAnswerTextFirst + "</span></td><td class=\"tdFirstColAnswer\" style=\"width:15px;\">" + StudyAns + "</td></td><td class=\"tdFirstColAnswer\" style=\"width:15px;\">[Đúng]</td></tr>";
                            }
                            else
                            {
                                //AnsText += "  <tr><td class=\"tdFirstColAnswer\" style=\"width:15px;\"></td><td><span " + CssCorrect + ">" + tAnswerTextFirst + "</span></td></tr>";
                                AnsText += "  <tr><td><span " + CssCorrect + ">" + tAnswerTextFirst + "</span></td><td class=\"tdFirstColAnswer\" style=\"width:15px;\">" + StudyAns + "</td></td><td class=\"tdFirstColAnswer\" style=\"width:15px;\">[Sai]</td></tr>";
                            }
                        }
                    }
                    AnsText += "</table>" +
                               "</div>";
                }

                //************** crosslink *****************************
                if (examQuestionCls.Type.ToLower().Equals("crosslink"))
                {
                    DataTable dtItemsPA2 = new ExamQuestionBll().ReadingExamAnswerByAnswerTextLast(SiteId, examQuestionCls.ExamQuestionId);
                    string[] Answers = examQuestionCls.StudentAnswer.Split(new char[] { '|' });// 1:8BEBC1CB-C33B-4990-ACB4-E570A3DD4A85|2:41BF0513-91A6-49BA-B973-C73C0C34E27D|3:9B3345AC-7319-4A08-AB9B-8061A610EBAE|                    
                    Header =
                                "  <tr>" +
                                "       <td class=\"tdFirstColAnswer\" style=\"width:10px;\"></td> " +
                                "       <td></td>" +
                                "       <td width='30px'></td>" +
                                "       <td><b>Sinh viên trả lời</b></td>" +
                                "       <td><b>Câu trả lời</b></td>" +
                                "       <td></td>" +
                                "  </tr>";

                    AnsText = "";
                    AnsText +=
                        "<div class=cssHelpExam>Điền vào ô trống số thứ tự của cột bên trái tương ứng với câu trả lời đúng nhất cho các phương án dưới đây</div>" +
                        "<div id=divBestAnswerContent>" +
                        "<input type=hidden id=txtMaxItemAns value=\"" + items + "\">" +
                        "<table class=cssUlAnswerText>";
                    for (int iIndex = 0; iIndex < items; iIndex++)
                    {
                        string tExamAnswerId = (string)dtItems.Rows[iIndex]["ExamAnswerId"];
                        string tAnswerTextFirst = (string)dtItems.Rows[iIndex]["AnswerTextFirst"];

                        string pa2AnswerTextFirst = (string)dtItemsPA2.Rows[iIndex]["AnswerTextLast"];
                        string pa2ExamAnswerId = (string)dtItemsPA2.Rows[iIndex]["ExamAnswerId"];

                        string Value = string.Empty;
                        int tCorrectAnswer = int.Parse(dtItemsPA2.Rows[iIndex]["IndexOrder"].ToString());

                        for (int iIndexCheck = 0; iIndexCheck < Answers.Length; iIndexCheck++)
                        {
                            if (Answers[iIndexCheck].IndexOf(":") != -1) //1:8BEBC1CB-C33B-4990-ACB4-E570A3DD4A85
                            {
                                string[] AnswersPA2 = Answers[iIndexCheck].Split(new char[] { ':' });

                                if (AnswersPA2[1].Trim().Length > 0)
                                {
                                    if (AnswersPA2[1].ToLower().Equals(pa2ExamAnswerId.ToLower()))
                                    {
                                        Value = AnswersPA2[0];
                                        break;
                                    }
                                }
                            }
                        }
                        if (OExamRoomStudent.FinishExam == 0)
                        {
                            AnsText +=
                            "  <tr>" +
                            "       <td class=\"tdFirstColAnswer\" style=\"width:10px;\">" +
                            "       <input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\">" + (iIndex + 1) + ".</td> " +
                            "       <td>" + tAnswerTextFirst + "</td>" +
                            "       <td width='30%'></td>" +
                            "       <td>" +
                            "       <input type=hidden id=txtPA2ItemAnsId" + iIndex + " value=\"" + pa2ExamAnswerId + "\">" +
                            "       <select id=drpCrossLink" + iIndex + ">" +
                            "           <option value=-1>--Chọn câu trả lời--</option>";
                            for (int i = 1; i <= items; i++)
                            {
                                Selected = "";
                                if (!string.IsNullOrEmpty(Value))
                                {
                                    if (i == int.Parse(Value))
                                    {
                                        Selected = "Selected";
                                    }
                                }

                                AnsText += "<option value=" + i + " " + Selected + ">" + i + "</option>";

                            }
                            AnsText +=
                            "       </select>" +
                            "       </td>" +
                            "       <td>" + pa2AnswerTextFirst + "</td>" +
                            "  </tr>";
                        }
                        else
                        {
                            AnsText += Header;
                            Header = string.Empty;
                            AnsText +=
                               "  <tr>" +
                               "       <td class=\"tdFirstColAnswer\" style=\"width:10px;\">" + (iIndex + 1) + ".</td> " +
                               "       <td>" + tAnswerTextFirst + "</td>" +
                               "       <td width='30px'></td>" +
                               "       <td style=''>" + Value + "</td>" +
                               "       <td>" + tCorrectAnswer + "</td>" +
                               "       <td>" + pa2AnswerTextFirst + "</td>" +
                               "  </tr>";
                        }
                    }
                    AnsText += "</table>" +
                               "</div>";
                }

                //************** image *****************************

                if (examQuestionCls.Type.ToLower().Equals("image"))
                {
                    try
                    {
                        DataTable dtItemsPA2 = new ExamQuestionBll().ReadingExamAnswerByAnswerTextLast(SiteId, examQuestionCls.ExamQuestionId);
                        if (dtItemsPA2.Rows.Count > 0)
                        {
                            string[] StudentAnswer = examQuestionCls.StudentAnswer.Split(new char[] { '|' });// 1:8BEBC1CB-C33B-4990-ACB4-E570A3DD4A85|2:41BF0513-91A6-49BA-B973-C73C0C34E27D|3:9B3345AC-7319-4A08-AB9B-8061A610EBAE|                    
                            Header =
                                        "  <tr>" +
                                        "       <td class=\"tdFirstColAnswer\" style=\"width:10px;\"></td> " +
                                        "       <td></td>" +
                                        "       <td width='30px'></td>" +
                                        "       <td><b>Sinh viên trả lời</b></td>" +
                                        "       <td><b>Câu trả lời</b></td>" +
                                        "       <td></td>" +
                                        "  </tr>";

                            AnsText = "";

                            string QuestionId = (string)dtItemsPA2.Rows[0]["CorrectAnswer"];
                            string ImgName = (string)dtItemsPA2.Rows[0]["ImageFileName"];

                            string HttpDataRoot = Portal.Web.Utility.WebConfig.HttpDataRoot(OSiteParam);
                            HttpDataRoot = HttpDataRoot + "/Cms/" + WebSessionUtility.GetCurrentLoginUser().AssetCode + "/" + QuestionId;
                            string ImageUrl = string.Empty;
                            if (!string.IsNullOrEmpty(QuestionId) && !string.IsNullOrEmpty(ImgName))
                            {
                                ImageUrl = HttpDataRoot + "/" + ImgName;
                            }

                            AnsText +=
                                "<div class=cssHelpExam>Điền vào ô trống số thứ tự của cột bên trái tương ứng với câu trả lời đúng nhất cho các phương án dưới đây</div>" +
                                "<div id=divBestAnswerContent>" +
                                "<input type=hidden id=txtMaxItemAns value=\"" + items + "\">" +
                                "<table class=cssUlAnswerText>" +
                                "<th colspan=5><image src='" + ImageUrl + "' class='imgexam' /></th>";
                            for (int iIndex = 0; iIndex < items; iIndex++)
                            {
                                string tExamAnswerId = (string)dtItems.Rows[iIndex]["ExamAnswerId"];
                                string tAnswerTextFirst = (string)dtItems.Rows[iIndex]["AnswerTextFirst"];

                                string pa2AnswerTextFirst = (string)dtItemsPA2.Rows[iIndex]["AnswerTextLast"];
                                string pa2ExamAnswerId = (string)dtItemsPA2.Rows[iIndex]["ExamAnswerId"];

                                string Value = string.Empty;
                                int tCorrectAnswer = int.Parse(dtItemsPA2.Rows[iIndex]["IndexOrder"].ToString());

                                for (int iIndexCheck = 0; iIndexCheck < StudentAnswer.Length; iIndexCheck++)
                                {
                                    if (StudentAnswer[iIndexCheck].IndexOf(":") != -1) //1:8BEBC1CB-C33B-4990-ACB4-E570A3DD4A85
                                    {
                                        string[] AnswersPA2 = StudentAnswer[iIndexCheck].Split(new char[] { ':' });

                                        if (AnswersPA2[1].Trim().Length > 0)
                                        {
                                            if (AnswersPA2[1].ToLower().Equals(pa2ExamAnswerId.ToLower()))
                                            {
                                                try
                                                {
                                                    Value = AnswersPA2[0];
                                                }
                                                catch { }
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (OExamRoomStudent.FinishExam == 0)
                                {
                                    AnsText +=
                                    "  <tr>" +
                                    "       <td class=\"tdFirstColAnswer\" style=\"width:10px;\">" +
                                    "       <input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\">" + (iIndex + 1) + ".</td> " +
                                    "       <td>" + tAnswerTextFirst + "</td>" +
                                    "       <td width='30%'></td>" +
                                    "       <td>" +
                                    "       <input type=hidden id=txtPA2ItemAnsId" + iIndex + " value=\"" + pa2ExamAnswerId + "\">" +
                                    "       <select id=drpCrossLink" + iIndex + ">" +
                                    "           <option value=-1>--Chọn câu trả lời--</option>";
                                    for (int i = 1; i <= items; i++)
                                    {
                                        Selected = "";
                                        if (!string.IsNullOrEmpty(Value))
                                        {
                                            if (i == int.Parse(Value))
                                            {
                                                Selected = "Selected";
                                            }
                                        }
                                        AnsText += "<option value=" + i + " " + Selected + ">" + i + "</option>";
                                    }
                                    AnsText +=
                                    "       </select>" +
                                    "       </td>" +
                                    "       <td>" + pa2AnswerTextFirst + "</td>" +
                                    "  </tr>";
                                }
                                else
                                {
                                    AnsText += Header;
                                    Header = string.Empty;
                                    AnsText +=
                                       "  <tr>" +
                                       "       <td class=\"tdFirstColAnswer\" style=\"width:10px;\">" + (iIndex + 1) + ".</td> " +
                                       "       <td>" + tAnswerTextFirst + "</td>" +
                                       "       <td width='30px'></td>" +
                                       "       <td style=''>" + Value + "</td>" +
                                       "       <td>" + tCorrectAnswer + "</td>" +
                                       "       <td>" + pa2AnswerTextFirst + "</td>" +
                                       "  </tr>";
                                }
                            }
                            AnsText += "</table>" +
                                       "</div>";
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("ERROR: " + ex.Message.ToString());
                    }
                }
                //if (examQuestionCls.Type.ToLower().Equals("image"))
                //{
                //    DataTable dtItemsPA2 = new ExamQuestionBll().ReadingExamAnswerByAnswerTextLast(SiteId, examQuestionCls.ExamQuestionId);
                //    string[] Answers = examQuestionCls.StudentAnswer.Split(new char[] { '|' });// 1:8BEBC1CB-C33B-4990-ACB4-E570A3DD4A85|2:41BF0513-91A6-49BA-B973-C73C0C34E27D|3:9B3345AC-7319-4A08-AB9B-8061A610EBAE|                    

                //    AnsText = "";
                //    AnsText +=
                //        "<div class=cssHelpExam>Điền vào ô trống số thứ tự của cột bên trái tương ứng với câu trả lời đúng nhất cho các phương án dưới đây</div>" +
                //        "<div id=divBestAnswerContent>" +
                //        "<input type=hidden id=txtMaxItemAns value=\"" + items + "\">" +
                //        "<table class=cssUlAnswerText>";
                //    for (int iIndex = 0; iIndex < items; iIndex++)
                //    {
                //        string tExamAnswerId = (string)dtItems.Rows[iIndex]["ExamAnswerId"];
                //        string tAnswerTextFirst = (string)dtItems.Rows[iIndex]["AnswerTextFirst"];

                //        string pa2AnswerTextFirst = (string)dtItemsPA2.Rows[iIndex]["AnswerTextLast"];
                //        string pa2ExamAnswerId = (string)dtItemsPA2.Rows[iIndex]["ExamAnswerId"];

                //        string QuestionId = (string)dtItemsPA2.Rows[iIndex]["CorrectAnswer"];

                //        string HttpDataRoot = Portal.Web.Utility.WebConfig.HttpDataRoot(OSiteParam);
                //        HttpDataRoot = HttpDataRoot + "/Cms/" + WebSessionUtility.GetCurrentLoginUser().AssetCode + "/" + QuestionId;
                //        string ImageUrl = string.Empty;
                //        if (!string.IsNullOrEmpty(pa2AnswerTextFirst))
                //        {
                //            ImageUrl = HttpDataRoot + "/" + pa2AnswerTextFirst;
                //        }

                //        string Value = string.Empty;
                //        int tCorrectAnswer = int.Parse(dtItemsPA2.Rows[iIndex]["IndexOrder"].ToString());

                //        for (int iIndexCheck = 0; iIndexCheck < Answers.Length; iIndexCheck++)
                //        {
                //            if (Answers[iIndexCheck].IndexOf(":") != -1) //1:8BEBC1CB-C33B-4990-ACB4-E570A3DD4A85
                //            {
                //                string[] AnswersPA2 = Answers[iIndexCheck].Split(new char[] { ':' });

                //                if (AnswersPA2[1].Trim().Length > 0)
                //                {
                //                    if (AnswersPA2[1].ToLower().Equals(pa2ExamAnswerId.ToLower()))
                //                    {
                //                        Value = AnswersPA2[0];
                //                        break;
                //                    }
                //                }
                //            }
                //        }

                //        if (OExamRoomStudent.FinishExam == 0)
                //        {
                //            AnsText +=
                //                "  <tr>" +
                //                "       <td class=\"tdFirstColAnswer\" style=\"width:10px;\">" +
                //                "       <input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\">" + (iIndex + 1) + ".</td> " +
                //                "       <td>" + tAnswerTextFirst + "</td>" +
                //                "       <td width='30%'></td>" +
                //                "       <td>" +
                //                "       <input type=hidden id=txtPA2ItemAnsId" + iIndex + " value=\"" + pa2ExamAnswerId + "\">" +
                //                 "       <select id=drpCrossLink" + iIndex + ">" +
                //            "           <option value=-1>--Chọn câu trả lời--</option>";

                //            for (int i = 1; i <= items; i++)
                //            {
                //                Selected = "";
                //                if (!string.IsNullOrEmpty(Value))
                //                {
                //                    if (i == int.Parse(Value))
                //                    {
                //                        Selected = "Selected";
                //                    }
                //                }

                //                AnsText += "<option value=" + i + " " + Selected + ">" + i + "</option>";
                //            }
                //            AnsText +=
                //            "       </select>" +
                //                "       </td>" +
                //                "       <td><image src='" + ImageUrl + "' class='imgexam' /></td>" +
                //                "  </tr>";
                //        }
                //        else
                //        {
                //            AnsText += Header;
                //            Header = string.Empty;
                //            AnsText +=
                //                "  <tr>" +
                //                "       <td class=\"tdFirstColAnswer\" style=\"width:10px;\">" + (iIndex + 1) + ".</td> " +
                //                "       <td>" + tAnswerTextFirst + "</td>" +
                //                "       <td width='30%'></td>" +
                //                "       <td>" + Value + "</td>" +
                //                "       <td>" + tCorrectAnswer + "</td>" +
                //                "       <td><image src='" + ImageUrl + "' class='imgexam' /></td>" +
                //                "  </tr>";
                //        }
                //    }
                //    AnsText += "</table>" +
                //               "</div>";
                //}

                //************** truefalse *****************************
                if (examQuestionCls.Type.ToLower().Equals("truefalse"))
                {
                    //DataTable dtItems = new ExamQuestionBll().ReadingExamAnswer(SiteId, examQuestionCls.ExamQuestionId);
                    string[] Answers = examQuestionCls.StudentAnswer.Split(new char[] { '|' });

                    AnsText = "<div class=cssHelpExam>Chọn cả phương án đúng và sai trong những phương án dưới đây</div>";
                    AnsText +=
                             "<div id=divBestAnswerContent>" +
                             "<input type=hidden id=txtMaxItemAns value=\"" + items + "\">" +
                             "<table class=cssUlAnswerText>";

                    Header = "  <tr><td class=\"tdFirstColAnswer\" style=\"width:60%;\"></td><td style=\"width:140px;\"><b>Sinh viên trả lời</b></td><td style=\"width:140px;\"><b>Câu trả lời</b></td></tr>";
                    string StudentAnswer = string.Empty;
                    for (int iIndex = 0; iIndex < items; iIndex++)
                    {
                        string tExamAnswerId = (string)dtItems.Rows[iIndex]["ExamAnswerId"];
                        string tAnswerTextFirst = (string)dtItems.Rows[iIndex]["AnswerTextFirst"];
                        bool CheckMarked = false;
                        for (int iIndexCheck = 0; iIndexCheck < Answers.Length; iIndexCheck++)
                        {
                            if (Answers[iIndexCheck].Trim().Length > 0)
                            {
                                if (Answers[iIndexCheck].Equals(tExamAnswerId))
                                {
                                    CheckMarked = true;
                                }
                            }
                        }
                        if (OExamRoomStudent.FinishExam == 0)
                        {
                            if (examQuestionCls.StudentAnswer.TrimEnd().Length > 0)
                            {
                                if (CheckMarked)
                                {
                                    AnsText +=
                                        "   <tr><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><td style='width:80px'>" + tAnswerTextFirst + "</td><td>" +
                                        "       <select id=drpYesNo" + iIndex + ">" +
                                        "           <option value=-1>--Chọn câu trả lời--</option>" +
                                        "           <option value=0>Sai</option>" +
                                        "           <option value=1 selected>Đúng</option>" +
                                        "       </select>" +
                                        "   </td></tr>";
                                }
                                else
                                {
                                    AnsText +=
                                        "  <tr><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><td style='width:80px'>" + tAnswerTextFirst + "</td><td>" +
                                        "<select id=drpYesNo" + iIndex + ">" +
                                        "     <option value=-1>--Chọn câu trả lời--</option>" +
                                        "     <option value=0 selected>Sai</option>" +
                                        "     <option value=1 >Đúng</option>" +
                                        "</select>" +
                                        "</td></tr>";
                                }
                            }
                            else
                            {
                                AnsText += "  <tr><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><td style='width:80px'>" + tAnswerTextFirst + "</td><td>" +
                                "<select id=drpYesNo" + iIndex + ">" +
                                "     <option value=-1>--Chọn câu trả lời--</option>" +
                                "     <option value=0 >Sai</option>" +
                                "     <option value=1 >Đúng</option>" +
                                "</select>" +
                                "</td></tr>";
                            }
                        }
                        else
                        {
                            AnsText += Header;
                            Header = string.Empty;
                            string tCorrectAnswer = (string)dtItems.Rows[iIndex]["CorrectAnswer"];
                            string CssCorrect = "";
                            string StudyAns = string.Empty;
                            string TrueAns = string.Empty;
                            if (examQuestionCls.StudentAnswer.TrimEnd().Length > 0)
                            {
                                if (CheckMarked)
                                {
                                    StudyAns = "Đúng";
                                }
                                else
                                {
                                    StudyAns = "Sai";
                                }
                            }
                            else
                            {
                                StudentAnswer = "<br><b>Chưa có câu trả lời</b>";
                            }
                            if (tCorrectAnswer.Equals("YES"))
                            {
                                CssCorrect = " class=\"cssCorrectAnsLine\"";
                                TrueAns = "[Đúng]";
                            }
                            else
                            {
                                TrueAns = "[Sai]";
                            }
                            AnsText += "  <tr><td '" + CssCorrect + "'>" + tAnswerTextFirst + "</span></td><td class=\"tdFirstColAnswer\" style=\"width:15px;\">" + StudyAns + "</td><td class=\"tdFirstColAnswer\" style=\"width:15px;\">" + TrueAns + "</td></tr>";
                        }
                    }

                    AnsText += "</table>" +
                                "<div class=cssHelpExam>" + StudentAnswer + "</div>" +
                               "</div>";
                }

                if (examQuestionCls.Type.ToLower().Equals("LargeFreeText".ToLower()))
                {
                    AnsText =
                        "<div class=cssHelpExam>Vui lòng làm bài vào ô phía dưới</div>" +
                        "<textarea id=txtFreeTextContent>" + examQuestionCls.StudentAnswer + "</textarea>";
                }
                if (examQuestionCls.Type.ToLower().Equals("freetext"))
                {
                    AnsText = "<textarea id=txtFreeTextContent>" + examQuestionCls.StudentAnswer + "</textarea>";
                }


                int ut = OExamRoomStudent.UseTime;
                //ut = ut * 60;
                int TotalExamTime = OExamRoomStudent.TotalExamTime;
                int RemainTime = TotalExamTime - ut;

                string[] allStatusId = new string[]{
                    "All","Done","NeedReview"
                };

                DataTable dtExamQuestion = new ExamQuestionBll().ReadingExamQuestion(SiteId, ExamRoomStudentId);

                string PageHtml = "<div class=cssPagingDoExam>" +
                                  " <ul>\r\n";
                for (int iIndexRecord = 0; iIndexRecord < dtExamQuestion.Rows.Count; iIndexRecord++)
                {
                    string ClassPaging = "class=NotExam";
                    int MarkedNeedReview = (int)dtExamQuestion.Rows[iIndexRecord]["MarkedNeedReview"];

                    if (MarkedNeedReview == 1)
                    {
                        ClassPaging = "class=ExamNeedReview";
                    }
                    string StudentAnswer = "";
                    try
                    {
                        StudentAnswer = (string)dtExamQuestion.Rows[iIndexRecord]["StudentAnswer"];
                    }
                    catch
                    {
                    }

                    if (StudentAnswer.Trim().Length > 0)
                    {
                        ClassPaging = "class=ExamDone";
                        if (MarkedNeedReview == 1)
                        {
                            ClassPaging = "class=ExamNeedReview";
                        }
                    }
                    if (OExamRoomStudent.FinishExam == 1)
                    {
                        int CorrectAnswer = 0;
                        if (dtExamQuestion.Rows[iIndexRecord]["CorrectAnswer"] != DBNull.Value)
                        {
                            CorrectAnswer = int.Parse(dtExamQuestion.Rows[iIndexRecord]["CorrectAnswer"].ToString());
                        }
                        if (CorrectAnswer == 1)
                        {
                            ClassPaging = "class=ExamDoneRight";
                        }
                        else
                        {
                            ClassPaging = "class=ExamDoneWrong";
                        }
                    }

                    PageHtml += "<li><a href=\"javascript:DoGoQuestion('" + ExamRoomStudentId + "','" + g + "'," + iIndexRecord + ");\" " + ClassPaging + ">" + (iIndexRecord + 1).ToString().PadLeft(2, '0') + "</a></li>";
                }

                PageHtml += "</ul>\r\n" +
                          "</div>\r\n";

                string RetHtml =
                    "<input type=hidden id=txtQuestionType value=\"" + examQuestionCls.Type.ToLower() + "\">" +
                    "<input type=hidden id=txtExamRoomStudentId value=\"" + ExamRoomStudentId + "\">";
                if (OExamRoomStudent.FinishExam == 0)
                {
                    RetHtml +=
                        "<div id=divExamInfo>\r\n" +
                        "       <span id=spanExamPersonalInfo>\r\n" +
                        "       Thời gian còn lại: <span id=divRemainExamTime>&nbsp;" + ConvertSecondToMinutes(RemainTime) + "</span>&nbsp;" + FinishButton + "\r\n" +
                        "</div>\r\n";
                }
                else
                {
                    RetHtml +=
                        "<div id=divExamInfo>\r\n" +
                        "       <span id=spanExamPersonalInfo>\r\n" +
                        "       Tổng số điểm của bài thi đạt " + OExamRoomStudent.DonePoint.ToString("#,##0") + " / " + OExamRoomStudent.TotalPoint.ToString("#,##0") + " <input type=button class=button style=\"height:22px;\" value=\"Làm bài khác\" onclick=\"javascript:ClientMakeNewExam();\">\r\n" +
                        "</div>\r\n";
                }
                RetHtml +=
                    "<div id=divExamInfoBody>\r\n" +
                    "   <div id=divExamInfoContent>\r\n";


                string SrcUrl = WebConfig.GetConfigFromXml(OSiteParam, "SrcUrl");
                string ToUrl = WebConfig.GetConfigFromXml(OSiteParam, "ToUrl");
                if (string.IsNullOrEmpty(ToUrl))
                {
                    ToUrl = OSiteParam.HttpRoot;
                }
                if (!string.IsNullOrEmpty(SrcUrl))
                {
                    examQuestionCls.Question = examQuestionCls.Question.Replace(SrcUrl, ToUrl);
                }
                string MarkText =
                    "<div class=CssMarkForReview>" +
                    "   <table>" +
                    "       <tr>" +
                    "           <td>Đánh dấu để xem lại</td>" +
                    "           <td><input id=chkNeedReview onchange=javascript:DoCheckNeedReview('" + examQuestionCls.ExamQuestionId + "','" + ExamRoomStudentId + "'); type=checkbox style=\"border:solid 1px silver;padding:1px;\" " + CheckedReviewText + "></td>" +
                    "       </tr>\r\n" +
                    "   </table>\r\n" +
                    "</div>";
                if (OExamRoomStudent.FinishExam == 1)
                {
                    MarkText = "";
                }

                string ExamQuestionTitle =
                    "   <div class=cssExamQuestionTitle>Câu " + (qn + 1) + ":<br>" + examQuestionCls.Title + " (" + examQuestionCls.MaxPoint.ToString("#,##0") + " điểm)</div>";
                string ExamQuestion = examQuestionCls.Question;
                if (ExamQuestion.ToLower().Trim().Equals(examQuestionCls.Title.Trim().ToLower()))
                {
                    ExamQuestion = "";
                }
                if (examQuestionCls.Type.Equals("flash"))
                {
                    //doan nay lay flash
                    string FlashContent = GetEmbbedContent(SiteId, examQuestionCls.ExamQuestionId);
                    ExamQuestionTitle =
                    "   <div class=cssExamQuestionTitle>Câu " + (qn + 1) + ": " + examQuestionCls.MaxPoint.ToString("#,##0") + " điểm</div>" +
                    "   <div class=\"CssFlashContent\">\r\n" +
                    "       <div class=\"CssFlashContentImage\">" + FlashContent + "</div>\r\n" +
                    "   </div>\r\n";
                }
                string StatusAnswer = "";

                if (OExamRoomStudent.FinishExam == 1)
                {
                    string AnswerText = "";
                    if (int.Parse(examQuestionCls.CorrectAnswer) == 0)
                    {
                        AnswerText = "Trả lời sai";
                        if (examQuestionCls.Type.Equals("flash"))
                        {
                            AnswerText += " / Câu trả lời: " + examQuestionCls.TeacherFlashAnswer;
                        }
                        StatusAnswer = " <span class=cssWrongAns>=>" + AnswerText + " </span>";
                    }
                    if (int.Parse(examQuestionCls.CorrectAnswer) == 1)
                    {
                        AnswerText = "Trả lời đúng";
                        if (examQuestionCls.Type.Equals("flash"))
                        {
                            AnswerText += " / đáp án: " + examQuestionCls.TeacherFlashAnswer;
                        }
                        StatusAnswer = " <span class=cssRightAns>=>" + AnswerText + "</span>";
                    }
                    if (int.Parse(examQuestionCls.CorrectAnswer) == -1)
                    {
                        AnswerText = "Không có câu trả lời";
                        if (examQuestionCls.Type.Equals("flash"))
                        {
                            AnsText += " / Câu trả lời: " + examQuestionCls.TeacherFlashAnswer;
                        }
                        StatusAnswer = " <span class=cssWrongAns>=>" + AnswerText + "</span>";
                    }
                }

                RetHtml += "<div class=CssDivResultInfo>" + StatusAnswer + "</div>";

                if (examQuestionCls.IsMemory == 1)
                {
                    if (examQuestionCls.StartMemory == 1)
                    {
                        RetHtml += ExamQuestionTitle;
                    }
                    else
                    {
                        string cButton = "<input onclick=javascript:DoStartMemory('" + ExamRoomStudentId + "','" + examQuestionCls.ExamQuestionId + "','" + g + "'," + CurrentIndex + "); type=button value=\"Bắt đầu\">";
                        RetHtml +=
                            ExamQuestionTitle +
                                " <div style=\"text-align:left;\">" + ExamQuestion + "</div>";

                    }
                }
                else
                {
                    if (examQuestionCls.Question.Trim().Length == 0)
                    {
                        RetHtml += ExamQuestionTitle;
                    }
                    else
                    {
                        RetHtml +=
                            ExamQuestionTitle +
                            "       <div style=\"text-align:left;\">" + ExamQuestion + "</div>";
                    }
                }

                RetHtml +=
                    "       <div class=cssExamAnswer>" + AnsText + "</div>\r\n" +
                    "   </div>\r\n" +
                    "</div>\r\n";

                if (OExamRoomStudent.FinishExam == 0)
                {
                    RetHtml +=
                        "<script language=javascript>\r\n" +
                        "       ProgressBarIndex=0;\r\n" +
                        "       function detectRemainTime(ExamRoomStudentId)\r\n" +
                        "       {\r\n" +
                        "           SiteId='" + SiteId + "';\r\n" +
                        "           document.getElementById(\"divRemainExamTime\").innerHTML=Portal.Exam.Render.DoExamRenderBll.ServerSideGetRemainTimeExam(SiteId, ExamRoomStudentId).value;\r\n" +
                        "           setTimeout(\"detectRemainTime('" + ExamRoomStudentId + "')\",60000);\r\n" +
                        "       }\r\n" +

                        "</script>\r\n" +
                        "<script language=javascript>\r\n" +
                        "       detectRemainTime(\"" + ExamRoomStudentId + "\");\r\n" +
                        "</script>";
                }

                string ExamInfo =
                    "<table>\r\n" +
                    " <tr>\r\n" +
                    "   <td>Tổng số câu:</td>\r\n" +
                    "   <td>" + OExamRoomStudent.TotalQuestion.ToString("#,##0") + "</td>\r\n" +
                    " </tr>\r\n" +
                    " <tr>\r\n" +
                    "   <td>Cần xem lại</td>\r\n" +
                    "   <td>" + OExamRoomStudent.TotalNeedReview.ToString("#,##0") + "</td>\r\n" +
                    " </tr>\r\n" +
                    " <tr>\r\n" +
                    "   <td>Đã làm:</td>\r\n" +
                    "   <td>" + OExamRoomStudent.TotalDone.ToString("#,##0") + "</td>\r\n" +
                    " </tr>\r\n" +
                    "</table>\r\n";

                string NextBack =
                     "<div class=CssCurrentQuestion><input class=button type=button " + BackUrl + " value=\"<\">&nbsp;Câu hỏi số [" + (qn + 1) + "/" + OExamRoomStudent.TotalQuestion + "]&nbsp;<input " + NextUrl + " type=button class=button value=\">\"></div>\r\n";
                if (OExamRoomStudent.FinishExam == 0)
                {
                    NextBack += MarkText;
                    if (examQuestionCls.Type.Equals("flash"))
                    {
                        string AnswerFlashTitle = "Bạn chưa làm! Xin nhập câu trả lời";
                        if (!string.IsNullOrEmpty(examQuestionCls.StudentAnswer))
                        {
                            AnswerFlashTitle = "Bạn đã chọn phương án <b>" + examQuestionCls.StudentAnswer + "</b>";
                        }
                        NextBack += "<div>" + AnswerFlashTitle + "<br><input id=txtAnswerFlash value=\"\"></div>\r\n" +
                                    "   <div class=CssGuideFlash><i>Nhập 1 câu trả lời đúng (Ví dụ: A) hoặc nhiều câu đúng ví dụ (A,C)</i></div>\r\n";

                    }

                    NextBack += " <div><input onclick=javascript:SaveAnswerItem('" + examQuestionCls.ExamQuestionId + "','" + ExamRoomStudentId + "','" + g + "'," + NextIndex + ",1,'" + examQuestionCls.Type + "'); type=button class=button value=\"Trả lời và làm câu tiếp theo\"></div>\r\n";
                }

                string StudentInfo =
                    "<table>\r\n" +
                    " <tr>\r\n" +
                    "   <td>Mã dự thi:</td>\r\n" +
                    "   <td>" + OExamRoomStudent.StudentCode + "</td>\r\n" +
                    " </tr>\r\n" +
                    " <tr>\r\n" +
                    "   <td>Tên sinh viên:</td>\r\n" +
                    "   <td>" + OExamRoomStudent.StudentName + "</td>\r\n" +
                    " </tr>\r\n" +
                    "</table>\r\n";

                string RetData = string.Format(LayoutText, ExamTitle, RetHtml, StudentInfo, PageHtml, ExamInfo, NextBack);
                return RetData;
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public static string GetCheckedBestAnswer(string SiteId, string ExamQuestionId, string ExamRoomStudentId, string ExamAnswerId)
        {

            ExamQuestionCls examQuestionCls = new ExamQuestionBll().CreateModel(SiteId, ExamQuestionId);
            DataTable dtItems = new ExamQuestionBll().ReadingExamAnswer(SiteId, ExamQuestionId);
            string AnsText = "<table class=cssUlAnswerText>" +
            "<input type=hidden id=txtMaxItemAns value=\"" + dtItems.Rows.Count + "\">";
            for (int iIndex = 0; iIndex < dtItems.Rows.Count; iIndex++)
            {
                string tExamAnswerId = (string)dtItems.Rows[iIndex]["ExamAnswerId"];
                string tAnswerTextFirst = (string)dtItems.Rows[iIndex]["AnswerTextFirst"];
                string CorrectAnswer = "NO";
                try
                {
                    CorrectAnswer = (string)dtItems.Rows[iIndex]["CorrectAnswer"];
                }
                catch { }


                if (tExamAnswerId.Equals(ExamAnswerId))
                {
                    AnsText += "  <tr><td><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><input id=txtItemAns" + iIndex + " onchange=javascript:DoCheckBestAnswer('" + examQuestionCls.ExamQuestionId + "','" + tExamAnswerId + "'); type=checkbox style=\"border:solid 1px silver;padding:1px;\" checked>&nbsp;" + tAnswerTextFirst + "</td></tr>";
                }
                else
                {
                    AnsText += "  <tr><td><input type=hidden id=txtItemAnsId" + iIndex + " value=\"" + tExamAnswerId + "\"><input id=txtItemAns" + iIndex + " onchange=javascript:DoCheckBestAnswer('" + examQuestionCls.ExamQuestionId + "','" + tExamAnswerId + "'); type=checkbox style=\"border:solid 1px silver;padding:1px;\">&nbsp;" + tAnswerTextFirst + "</td></tr>";
                }
            }
            AnsText += "</table>";
            return AnsText;
        }



        [AjaxPro.AjaxMethod]
        public static string ServerSideGetRemainTimeExam(string SiteId, string ExamRoomStudentId)
        {
            try
            {
                HasShutdownStarted = System.Environment.HasShutdownStarted;
                if (!HasShutdownStarted)
                {
                    new DoExamBll().UpdateUseTime(null, SiteId, ExamRoomStudentId);
                }

                int RemainTime = new DoExamBll().GetRemainTime(SiteId, ExamRoomStudentId);
                if (RemainTime < 0)
                {
                    RemainTime = 0;
                    new DoExamBll().SetFinishExam(null, SiteId, ExamRoomStudentId);
                }
                return ConvertSecondToMinutes(RemainTime);
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public static string ServerSideGetProgressBar(int ProgressBarIndex)
        {
            try
            {
                return "<div class=cssExamProgressBar style=\"text-align:center;color:white;background-color:maroon;width:" + (ProgressBarIndex * 5) + "px;\">" + (ProgressBarIndex + 1) + "</div>";
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public static string SaveYesNoAnswer(string SiteId, string ExamQuestionId, string ExamRoomStudentId, int YesNo)
        {
            try
            {
                if (YesNo == -1) throw new Exception("Chọn câu trả lời đúng hoặc sai");
                new ExamQuestionBll().SaveAnswerYesNo(null, SiteId, ExamQuestionId, YesNo);
                return "Ghi câu trả lời thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public static string SaveBestAnswer(string SiteId, string ExamQuestionId, string ExamRoomStudentId, string ExamAnswerId)
        {
            try
            {
                new ExamQuestionBll().SaveBestAnswer(null, SiteId, ExamQuestionId, ExamAnswerId);
                return "Ghi câu trả lời thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public static string SaveCrossLinkAnswer(string SiteId, string ExamQuestionId, string ExamRoomStudentId, string StudentAnswer, string StudentAnswerKeyValue)
        {
            try
            {
                new ExamQuestionBll().SaveCrossLinkAnswer(null, SiteId, ExamQuestionId, StudentAnswer, StudentAnswerKeyValue);
                return "Ghi câu trả lời thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        static bool CheckFlashAnswer(string FlashAnswer)
        {
            FlashAnswer = FlashAnswer.Trim();
            FlashAnswer = FlashAnswer.ToUpper();
            if (string.IsNullOrEmpty(FlashAnswer)) return true;
            for (int iIndex = 0; iIndex < FlashAnswer.Length; iIndex++)
            {
                if (FlashAnswer[iIndex].ToString().Equals("A") ||
                    FlashAnswer[iIndex].ToString().Equals("B") ||
                    FlashAnswer[iIndex].ToString().Equals("C") ||
                    FlashAnswer[iIndex].ToString().Equals("D") ||
                    FlashAnswer[iIndex].ToString().Equals("E") ||
                    FlashAnswer[iIndex].ToString().Equals("F") ||
                    FlashAnswer[iIndex].ToString().Equals("G") ||
                    FlashAnswer[iIndex].ToString().Equals("H") ||
                    FlashAnswer[iIndex].ToString().Equals("I") ||
                    FlashAnswer[iIndex].ToString().Equals("K") ||
                    FlashAnswer[iIndex].ToString().Equals(",") ||
                    FlashAnswer[iIndex].ToString().Equals(";"))
                {
                }
                else
                {
                    return false;
                }
            }
            return true;
        }

        [AjaxPro.AjaxMethod]
        public static string SaveFlash(string SiteId, string ExamQuestionId, string ExamRoomStudentId, string FlashAnswer)
        {
            try
            {
                FlashAnswer = FlashAnswer.Trim();
                FlashAnswer = FlashAnswer.ToUpper();
                bool Check = CheckFlashAnswer(FlashAnswer);
                if (Check == false) throw new Exception("Câu trả lời không hợp lệ. Nhập 1 phương án A hoặc B hoặc C ...  Hoặc nhiều phương án ví dụ: A,D");
                ExamQuestionCls oExamQuestionCls = new ExamQuestionBll().CreateModel(SiteId, ExamQuestionId);
                new ExamQuestionBll().SaveFlashAnswer(null, SiteId, ExamQuestionId, FlashAnswer, oExamQuestionCls.TeacherFlashAnswer);
                return "Ghi câu trả lời thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public static string SaveMultiChoice(string SiteId, string ExamQuestionId, string ExamRoomStudentId, string StudentAnswer)
        {
            try
            {
                new ExamQuestionBll().SaveMultiChoice(null, SiteId, ExamQuestionId, StudentAnswer);
                return "Ghi câu trả lời thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public static string SaveTrueFalse(string SiteId, string ExamQuestionId, string ExamRoomStudentId, string StudentAnswer)
        {
            try
            {
                new ExamQuestionBll().SaveTrueFalse(null, SiteId, ExamQuestionId, StudentAnswer);
                return "Ghi câu trả lời thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public static string SaveFreeText(string SiteId, string ExamQuestionId, string ExamRoomStudentId, string StudentAnswer)
        {
            try
            {
                new ExamQuestionBll().SaveFreeText(null, SiteId, ExamQuestionId, StudentAnswer);
                return "Ghi câu trả lời thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public static string GetConfirmFinishExamMsg(string SiteId)
        {
            return "Bạn đã chắc chắn kết thúc bài làm chưa?";
        }

        [AjaxPro.AjaxMethod]
        public static AjaxOut ServerSideSetFinishExam(string SiteId, string ExamRoomStudentId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                new DoExamBll().SetFinishExam(null, SiteId, ExamRoomStudentId);
                OAjaxOut.RetUrl = "ViewResultExamStudent.aspx?ExamRoomStudentId=" + ExamRoomStudentId;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod]
        public static string SetNeedReview(string SiteId, string ExamQuestionId, string ExamRoomStudentId, bool needReview)
        {
            try
            {
                new DoExamBll().SetNeedReview(null, SiteId, ExamQuestionId, needReview ? 1 : 0);
                return "";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public static string SetStartQuestionMemory(string SiteId, string ExamRoomStudentId, string ExamQuestionId, string g, int CurrentIndex)
        {
            try
            {
                new ExamQuestionBll().StartHidden(null, SiteId, ExamQuestionId);
                return GetFormContent(SiteId, ExamRoomStudentId, g, CurrentIndex);
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }
    }
}
